/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rpg;

import javax.swing.ImageIcon;

/**
 *
 * @author Emmanouil Samatas
 */
public class EnemyFactory {

    private static EnemyFactory instance;

    private EnemyFactory() {
    }

    public static synchronized EnemyFactory getInstance() {
        if (instance == null) {
            instance = new EnemyFactory();
        }
        return instance;
    }

    public Enemy createEnemy(int level) {

        Enemy enemy = new Enemy();
        enemy.setAttributes(GameCoreEngine.calculateAttributes(level));

        int vitality = enemy.getAttributes().get(GameCoreEngine.VITALITY);
        int strength = enemy.getAttributes().get(GameCoreEngine.STRENGTH);
        int intelligence = enemy.getAttributes().get(GameCoreEngine.INTELLIGENCE);

        int maxHealthPoints = GameCoreEngine.calculateHealth(vitality);
        int maxManaPoints = GameCoreEngine.calculateMana(intelligence);
        int currentHp = maxHealthPoints;
        enemy.setLevel(level);
        enemy.setHealthPoints(currentHp);
        enemy.setMaxHealthPoints(maxHealthPoints);

        enemy.setManaPoint(maxManaPoints);
        enemy.setMaxManaPoints(maxManaPoints);

        enemy.setDamage(GameCoreEngine.calculateDamage(strength, null));
        enemy.setDefence(GameCoreEngine.calculateDefence(strength,null));

        enemy.setExperience(GameCoreEngine.calculateExperience(level, maxHealthPoints));
        enemy.bigImageFileName = "simpleEnemy.png";
        ImageIcon ii = new ImageIcon(this.getClass().getResource(enemy.bigImageFileName));
        enemy.characterBigImage = ii.getImage();
        if (level < 10) {
            enemy.setCharacterName("Weak Monster");
        }
        if (level >= 10 && level < 30) {
            enemy.setCharacterName("Strong Monster");
        }
        if (level >= 30) {
            enemy.setCharacterName("Badass Monster");
        }

        return enemy;
    }

    // Needs refactoring!!!!! Do not use!
    public Enemy createBoss(int level) {
        Enemy enemy = new Enemy();
        enemy.setAttributes(GameCoreEngine.calculateAttributes(level));
        int vitality = enemy.getAttributes().get(GameCoreEngine.VITALITY) * GameCoreEngine.BOSS_MULTIPLIER;
        int strength = enemy.getAttributes().get(GameCoreEngine.STRENGTH) * GameCoreEngine.BOSS_MULTIPLIER;
        int intelligence = enemy.getAttributes().get(GameCoreEngine.INTELLIGENCE) * GameCoreEngine.BOSS_MULTIPLIER;

        enemy.setLevel(level);
        enemy.setHealthPoints(GameCoreEngine.calculateHealth(vitality));
        enemy.setManaPoint(GameCoreEngine.calculateMana(intelligence));
        enemy.setDamage(GameCoreEngine.calculateDamage(strength, null));
        enemy.setDefence(GameCoreEngine.calculateDefence(strength,null));
        enemy.setIsBoss(true);

        enemy.setExperience(level * 10 * GameCoreEngine.BOSS_XP_MULTIPLIER);
        if (level < 10) {
            enemy.setCharacterName("Andariel");
        }
        if (level >= 10 && level < 30) {
            enemy.setCharacterName("Duriel");
        }
        if (level >= 30) {
            enemy.setCharacterName("Diablo");
        }

        return enemy;
    }

    public static void main(String[] args) {
        EnemyFactory ef = EnemyFactory.getInstance();
        Enemy myCreep = ef.createEnemy(5);
        Enemy myBaddass = ef.createEnemy(60);
        // Enemy diablo = ef.createBoss(5);
        System.out.print("haha");
    }
}
